/*
 * test01.c
 *
 *  Created on: Sep 8, 2008
 *      Author: lindenb
 */
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "lang/morestdlib.h"
#include "lang/morestring.h"
#include "util/vector.h"
#include "util/debug.h"
#include "util/algorithm.h"

# define assertTrue(expr) do { if((expr)==false) {\
	fprintf(stderr,"Failure: %s %d : \""#expr"\"\n",__FILE__,__LINE__);\
	EXIT(EXIT_FAILURE);\
   } else { fprintf(stdout,"OK: %s %d : \""#expr"\"\n",__FILE__,__LINE__);}} while(false)

int main(int argc,char** argv)
{
int array_of_int[]={ 1, 2, 3, 3, 3, 5, 8 };
int array_of_int_size=sizeof(array_of_int)/sizeof(int);
int loop=0;
int i=0;
StringArrayPtr ptr=NULL;

debug_setDebugging(true);
assertTrue(sizeof(op_bool)==1);
assertTrue(sizeof(op_int8)==1);
assertTrue(sizeof(op_int16)==2);
assertTrue(sizeof(op_int32)==4);
assertTrue(sizeof(op_int64)==8);

/** Test Vector */
VectorHandler handler;
vectorHandler_init(&handler);
handler.item_size = sizeof(char*);
handler.dispose = Free;
handler.compare=strcmp;

VectorPtr vector= vector_new(&handler);

for( loop=0;loop< 100000;++loop)
	{
	vector_clear(vector);
	for( i=0;i<10;++i)
		{
		char *p= strfmt("Hello loop %d",i);
		vector_addElement(vector,(BytePtr)p);

		assert(vector_contains(vector,p));
		}
	}

for(i=0;i< vector_size(vector);++i)
	{
	char *p;
	char *p2= strfmt("Hello loop %d",i);
	vector_getElementAt(vector,i,&p);
	if(strcmp(p,p2)!=0) assertTrue(false);
	Free(p2);
	}

fprintf(stderr,"size = %d \n",array_of_int_size);
for(i=1;i<= 10;++i)
	{
	printf("searching for %d ",i);
	int L = lower_bound(array_of_int,array_of_int_size,sizeof(int),NULL,&i);
	printf("result : %d a[%d]=%d\n",L,L,array_of_int[L]);

	}

ptr= strSplit("A,T,G,C",',');
assertTrue(ptr!=NULL);
assertTrue(stringArray_size(ptr)==4);
assertTrue(strcmp(stringArray_at(ptr,0),"A")==0);
assertTrue(strcmp(stringArray_at(ptr,1),"T")==0);
assertTrue(strcmp(stringArray_at(ptr,2),"G")==0);
assertTrue(strcmp(stringArray_at(ptr,3),"C")==0);
assertTrue(strcmp(stringArray_at(ptr,3),"A")!=0);
fprintf(stdout,"Test Done.");
return 0;
}
